package com.zczc.service.impl;

import com.github.pagehelper.PageInfo;
import com.yishuifengxiao.common.tool.bean.BeanUtil;
import com.zczc.dao.api.MessageInfoDao;
import com.zczc.dto.MessageInfoDTO;
import com.zczc.dto.MessageInfoUpdateDTO;
import com.zczc.entity.MessageInfo;
import com.zczc.service.MessageInfoService;
import java.util.Calendar;
import java.util.List;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author:Mark
 * @Description:
 * @Date: Created on 15:01 2018-12-12
 * @Modify by:
 */
@Service
public class MessageInfoServiceImpl implements MessageInfoService {

  @Autowired
  private MessageInfoDao messageInfoDao;

  @Override
  public Boolean addMessageInfoSelective(MessageInfoDTO messageInfoDTO) {
    if(messageInfoDTO!=null){
      MessageInfo messageInfo = BeanUtil.copy(messageInfoDTO, new MessageInfo());
      messageInfo.setId(UUID.randomUUID().toString());
      messageInfo.setCreateTime(Calendar.getInstance().getTime());
      messageInfo.setPushTime(messageInfo.getPushTime()==null?Calendar.getInstance().getTime():messageInfo.getPushTime());
      messageInfo.setDeleted(false);
      return messageInfoDao.addMessageInfo(messageInfo)>0;
    }
    return false;
  }

  @Override
  public Boolean updateMessageInfoSelective(MessageInfoUpdateDTO messageInfoUpdateDTO) {
    if(messageInfoUpdateDTO!=null){
      MessageInfo messageInfo = BeanUtil.copy(messageInfoUpdateDTO, new MessageInfo());
      messageInfo.setUpdateTime(Calendar.getInstance().getTime());
      return messageInfoDao.updateMessageInfoSelective(messageInfo)>0;
    }
    return false;
  }

  @Override
  public PageInfo<MessageInfo> selectMessageInfoByPage(MessageInfo messageInfo, Integer pageSize,
      Integer pageNum) {
    pageSize=pageSize==null?20:pageSize;
    pageNum=pageNum==null?1:pageNum;
    return messageInfoDao.selectMessageInfoByPage(messageInfo,pageNum,pageSize);
  }

  @Override
  public Boolean deleteMessageInfoByIdLogic(List<String> ids) {
    if(ids!=null){
      return messageInfoDao.deleteMessageInfoByIdLogic(ids)>0;
    }
    return false;
  }
}
